#include "qwdlgmanual.h"

QWDlgManual::QWDlgManual(QWidget *parent)
    : QDialog(parent)
{
    initUI();
    initSignalSlots();
    setWindowTitle("Form created manually");
}

QWDlgManual::~QWDlgManual()
{

}
void QWDlgManual::setTextFontColor()
{
    QPalette ple = txtEdit->palette();
    if(rBtnBlack->isChecked())
        ple.setColor(QPalette::Text, Qt::black);
    else if(rBtnBlue->isChecked())
        ple.setColor(QPalette::Text, Qt::blue);
    else if(rBtnRed->isChecked())
        ple.setColor(QPalette::Text, Qt::red);
    else
        ple.setColor(QPalette::Text, Qt::black);
    txtEdit->setPalette(ple);
}

void QWDlgManual::on_chkBoxBold(bool checked)
{
    QFont font = txtEdit->font();
    font.setBold(checked);
    txtEdit->setFont(font);
}

void QWDlgManual::on_ChkBoxItalic(bool checked)
{
    QFont font = txtEdit->font();
    font.setItalic(checked);
    txtEdit->setFont(font);
}

void QWDlgManual::on_chkBoxUnder(bool checked)
{
    QFont font = txtEdit->font();
    font.setUnderline(checked);
    txtEdit->setFont(font);
}

void QWDlgManual::initUI()
{
    chkBoxBold = new QCheckBox("Underline");
    chkBoxItalic = new QCheckBox("Italic");
    chkBoxUnder = new QCheckBox("Underline");
    QHBoxLayout *HLay1 = new QHBoxLayout;
    HLay1->addWidget(chkBoxBold);
    HLay1->addWidget(chkBoxItalic);
    HLay1->addWidget(chkBoxUnder);
    //create radio
    rBtnBlack = new QRadioButton("Black");
    rBtnBlue = new QRadioButton("Blue");
    rBtnRed = new QRadioButton("Red");
    QHBoxLayout *HLay2 = new QHBoxLayout;
    HLay2->addWidget(rBtnBlack);
    HLay2->addWidget(rBtnBlue);
    HLay2->addWidget(rBtnRed);
    //create control buttons
    btnOK = new QPushButton(tr("确定"));
    btnCancel = new QPushButton("取消");
    btnClose = new QPushButton("关闭");
    QHBoxLayout *HLay3 = new QHBoxLayout;
    HLay3->addStretch();
    HLay3->addWidget(btnOK);
    HLay3->addWidget(btnCancel);
    HLay3->addStretch();
    HLay3->addWidget(btnClose);
    //create txtedit
    txtEdit = new QPlainTextEdit;
    txtEdit->setPlainText("Hello world\n\nIt is my demo");
    QFont font = txtEdit->font();
    font.setPointSize(20);
    txtEdit->setFont(font);
    //create layout
    QVBoxLayout *VLay = new QVBoxLayout;
    VLay->addLayout(HLay1);
    VLay->addLayout(HLay2);
    VLay->addWidget(txtEdit);
    VLay->addLayout(HLay3);
    setLayout(VLay);
}

void QWDlgManual::initSignalSlots()
{
    connect(rBtnBlack, SIGNAL(clicked(bool)), this, SLOT(setTextFontColor()));
    connect(rBtnBlue, SIGNAL(clicked(bool)), this, SLOT(setTextFontColor()));
    connect(rBtnRed, SIGNAL(clicked(bool)), this, SLOT(setTextFontColor()));

    connect(chkBoxUnder, SIGNAL(clicked(bool)), this, SLOT(on_chkBoxUnder(bool)));
    connect(chkBoxBold, SIGNAL(clicked(bool)), this, SLOT(on_chkBoxBold(bool)));
    connect(chkBoxItalic, SIGNAL(clicked(bool)), this, SLOT(on_ChkBoxItalic(bool)));

    connect(btnCancel, SIGNAL(clicked()), this, SLOT(close()));
}
